$TITLE ('RTX-51 CLEAR SIGNAL SYSTEM CALL')
$SYMBOLS
$NOXREF
$NOCOND
$NOMOD51
$NORB
$PAGELENGTH(80) PAGEWIDTH(110)
;************************************************************************
;*									*
;*    R T X - 5 1  :  CLEAR SIGNAL SYSTEM CALL                          *
;*							     		*
;*----------------------------------------------------------------------*
;*                                                                      *
;*    Filename     :   RTXCLEAR.A51                                     *
;*    Language     :   Keil A-51                                        *
;*    Dev. system  :   Keil uVision2                                    *
;*    Targetsystem :   Any system based upon 8051 up                    *
;*                                                                      *
;*    Purpose      :   Implements the os_clear_signal system-call       *
;*								     	*
;*----------------------------------------------------------------------*
;* Rev. |  Released   | Programmer    | Comments                        *
;*----------------------------------------------------------------------*
;*  0.1 |  16.1.90    | E. Glatz      | Changes for V3.18               *
;*  0.2 |   8.3.91    | Th. Fischler  | Changes for V4.0                *
;*      |             |               | C-51 parameter passing          *
;*      |  16.4.91    | Th. Fischler  | rtx_get_tid eliminated          *
;*  0.3 |  28.5.91    | Th. Fischler  | New file-name RTXCLEAR.A51      *
;*      |             |               | Changes for V4.0                *
;* 5.00 |  20.10.1994 | E. Glatz      | Release 5.00                    *
;* 7.00 |  13.11.2001 | T. Mueller    | Release 7.00                    *
;************************************************************************
;*    Copyright 1991 .. 2001 METTLER  &  FUCHS  AG,  CH-8953 Dietikon   *
;************************************************************************

$INCLUDE (RTXDEBUG.INC)
$INCLUDE (RTXIMASK.INC)

;*----------------------------------------------------------------------*
;*	I M P O R T S
;*----------------------------------------------------------------------*

$INCLUDE (RTXCONST.INC)
$INCLUDE (RTXEXTRN.INC)

;       FROM RTXDISP
EXTRN   CODE    (?RTX_REDISPATCH)


;*----------------------------------------------------------------------*
;*	E X P O R T S
;*----------------------------------------------------------------------*

PUBLIC  _os_clear_signal


;*----------------------------------------------------------------------*
;*	P R O C E D U R E S
;*----------------------------------------------------------------------*

;*----------------------------------------------------------------------*
;*      O S _ C L E A R _ S I G N A L
;*----------------------------------------------------------------------*
;*      Clears a possibly pending signal request for a particular task.
;*----------------------------------------------------------------------*
;*      Input:   - R7: signal owning task number
;*
;*      Output:  - Returns execution status in R7:
;*                      = OK
;*                      = NOT_OK -> task not found
;*----------------------------------------------------------------------*

?RTX?_os_clear_signal?RTXCLEAR  SEGMENT CODE
                                RSEG    ?RTX?_os_clear_signal?RTXCLEAR

_os_clear_signal:
               DBG_SYS_ENTRY
               RTX_EXCLUDE_INT
               SETB  ?RTX_SUPERVISOR_MODE       ; Supervisor_mode := on
               RTX_ALLOW_DRV_INT
               RTX_EXCLUDE_INT
               ; Check task-number
               MOV   A, R7
               SETB  C
               SUBB  A, #?RTX_MAXTASKN
               JC    EVAL_INTERNAL_NUM
               ; Number is greater than the maximum used task-number
               MOV   R7, #NOT_OK
               JMP   END_CLEAR

EVAL_INTERNAL_NUM:
               ; Evaluate the internal Task-Number
               MOV   DPH, #HIGH(?RTX_USER_NUM_TABLE)
               MOV   A, #LOW(?RTX_USER_NUM_TABLE)
               ADD   A, R7
               MOV   DPL, A
               ; DPTR -> user_num_table[user_num]
               MOVX  A, @DPTR
               CJNE  A, #NO_TASK, TASK_FOUND
               MOV   R7, #NOT_OK
               JMP   END_CLEAR                  ; Not a valid task
               

TASK_FOUND:    MOV   R7, A                      ; Internal task-num in R7
               ;  Set up ptr to task state
               MOV   A, R7
               RL    A
               RL    A
               ADD   A, #LOW (?RTX_STATE_TABLE)
               MOV   DPL, A
               MOV   DPH, #HIGH(?RTX_STATE_TABLE)
               MOVX  A, @DPTR
               ; Clear signal request bit
               ANL   A, #07FH
               MOVX  @DPTR, A
               MOV   R7, #OK

END_CLEAR:     JB    ?RTX_REQ_REDISPATCH, RED   ; Redispatch requested ?
					        ; No:
               CLR   ?RTX_SUPERVISOR_MODE       ; Supervisor_mode := OFF
               DBG_SYS_EXIT
               RTX_ALLOW_INT
               RET

RED:           CLR   ?RTX_FULL_CONTEXT
               JMP   ?RTX_REDISPATCH

;
;   END OF MODULE
;
	END
